<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui"
	xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
</h:head>
<h:body>

<ui:composition template="/layout.xhtml"> 

<ui:define name="content"> 

	<p:growl id="mensagem" showDetail="true" autoUpdate="true"
		closable="true" />
	<h:form id="formPrincipal">
	
		<ui:insert name="panelLista" > 

		</ui:insert> 
			
			<p:commandLink title="Incluir" oncomplete="dialogCadastrar.show()"
				update=":formCadastrar" immediate="false">
				<p:graphicImage value="/imagem/incluir.png" />
			</p:commandLink>

		<ui:insert name="tabelalLista" > 
				<ui:include src="/cabecalho.xhtml" /> 
		</ui:insert> 

			<p:dataTable id="tabela" var="item" value="#{cursoMB.lista}"
				paginator="true" rows="10" emptyMessage="Não há registros na lista"
				paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
				rowsPerPageTemplate="10,15,25,50,100">
				<f:facet name="header">Lista de Cursos</f:facet>
				<p:column headerText="ID" style="width: 10%;">					
					<h:outputText value="#{item.codigo}" />
				</p:column>
				<p:column headerText="Descricao" style="width: 40%;">
					<h:outputText value="#{item.descricao}" />
				</p:column>
				<p:column headerText="Valor" style="width: 15%;">
					<h:outputText value="#{item.valor}" />
				</p:column>
				<p:column headerText="Ações" style="width: 20%;" exportable="false">
					<p:commandLink title="Alterar" update=":formCadastrar"
						oncomplete="dialogCadastrar.show()" immediate="true">
						<p:graphicImage value="/imagem/alterar.png" />
						<f:setPropertyActionListener target="#{cursoMB.curso}"
							value="#{item}" />
					</p:commandLink>				
					<p:commandLink title="Excluir" update=":formExcluir:Excluir"
							oncomplete="confirmation.show()" immediate="false">
							<p:graphicImage value="/imagem/remover.png"  />
							<f:setPropertyActionListener target="#{cursoMB.curso}"
								value="#{item}" />
						</p:commandLink>
				</p:column>		
			</p:dataTable>
		</p:panel>
	</h:form>
	<!-- Formulário de Exclusão -->
	<h:form id="formExcluir">
		<p:confirmDialog id="Excluir" closable="true"
			message="Confirma a exclusão do registro: #{cursoMB.curso.descricao}?"
			header="Excluir" severity="alert" widgetVar="confirmation">
			<h:inputHidden value="#{cursoMB.curso.codigo}" />

			<p:commandButton id="btnConfirmar" value="Sim"
				oncomplete="confirmation.hide()" action="#{cursoMB.excluir}"
				update=":formPrincipal:tabela :mensagem" />
			<p:commandButton id="decline" value="Não"
				onclick="confirmation.hide()" type="button" />
		</p:confirmDialog>
	</h:form>
	<!-- Formulário de Exclusão -->

	<!-- Formulário de Cadastro -->
	<h:form id="formCadastrar">
		<p:dialog header="Cadastrar" widgetVar="dialogCadastrar" modal="false">
			<p:panelGrid id="panelCadastrar" columns="2">
				<p:outputLabel value="Código:" />
				<p:inputText id="codigo" readonly="#{facesContext.renderResponse}" value="#{cursoMB.curso.codigo}" label="Código:" >
				</p:inputText>
			
				<p:outputLabel for="descricao" value="Descrição:" />
				<p:inputText id="descricao" value="#{cursoMB.curso.descricao}" required="true">
				</p:inputText>
								
				<p:outputLabel value="Valor:" />
				<p:inputText id="valor" value="#{cursoMB.curso.valor}"  required="true">
				</p:inputText>
				
			</p:panelGrid>
			<p:commandButton value="Salvar" id="btnCadastrar"
				action="#{cursoMB.salvar}"
				update=":formPrincipal:tabela :mensagem"
				oncomplete="dialogCadastrar.hide()" />
		</p:dialog>
	</h:form>
</ui:define>
</ui:composition>
</h:body>
</html>